package com.concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

public class ConcurrentTest {
	
	public static void main(String[] args) throws InterruptedException, ExecutionException {
		
		Callable<String> callable = new MyTask();;
		FutureTask<String> task = new FutureTask<String>(callable);
		new Thread(task).start();
		System.out.println("------------");
		try {
			String string = task.get();
			System.out.println(string);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		System.out.println("------------");
		
//		ExecutorService executorService = Executors.newCachedThreadPool();
//		Future<String> submit = (Future<String>) executorService.submit(callable);
//		String string = submit.get();
//		System.out.println(string);
		
		
		
	}

}
class MyTask implements Callable<String>{

	public String call() throws Exception {
		Thread.sleep(5 * 1000);
		if(1==1){
			throw new RuntimeException();
		}
		return "yahoo";
	}
	
}